package org.cll.lagou.study.springbootdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.cll.lagou.study.springbootdemo.entity.Article;
import org.cll.lagou.study.springbootdemo.mapper.ArticleMapper;
import org.cll.lagou.study.springbootdemo.service.ArticleService;
import org.cll.lagou.study.springbootdemo.util.AssertUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/6/27 9:05
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    private static final Logger logger = LoggerFactory.getLogger(ArticleServiceImpl.class);

    private ArticleMapper articleMapper;

    @Autowired
    public ArticleServiceImpl(ArticleMapper articleMapper) {
        this.articleMapper = articleMapper;
    }

    @Override
    public Article getById(Integer id) {
        AssertUtil.isNotEmpty(id);
        logger.info("====== 根据主键查询");
        return articleMapper.getById(id);
    }

    @Override
    public List<Article> getAll() {
        return articleMapper.getAll();
    }

    @Override
    public PageInfo<Article> getByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Article> pageInfo = new PageInfo<>(articleMapper.getAll());
        return pageInfo;
    }
}
